package itbour.onetouchshow.activity.main;


import android.util.Log;

import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;

import java.util.HashMap;

import itbour.onetouchshow.base.mvp.BasePresenterImpl;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.utils.DeviceUtil;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.UIUtils;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class MainPresenter extends BasePresenterImpl<MainContract.View> implements MainContract.Presenter {

    public MainPresenter(MainContract.View view) {
        mvpView = view;
    }


    public void getHomeDetailsData() {
        L_.i("APP 基础信息  getHomeDetailsData===");
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("device", AppConst.ANDROID_DEVICE);
        HttpUtils.getInstance().executeGet(AppConfig.GET_APPBASE_INFO_V10, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                L_.i("APP 基础信息  response===" + response);
                if (mvpView != null) {
                    mvpView.loadSucceed(response);
                }
            }
        });
    }


    public void getAppBannerInfo() {
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("device", AppConst.ANDROID_DEVICE);
        String appVersionName = DeviceUtil.getAppVersionName(UIUtils.getContext());
        stringStringHashMap.put("appVer", appVersionName);
        HttpUtils.getInstance().executeGet(AppConfig.GETAPPBANNERINFO_V1_1, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                if (mvpView != null) {
                    // mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                //  L_.i("APP 基础信息  response==="+response);
                if (mvpView != null) {
                    mvpView.loadBannerSuccess(response);


                }
            }
        });
    }

    public void getAdDialogInfo() {
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("device", AppConst.ANDROID_DEVICE);
        String appVersionName = DeviceUtil.getAppVersionName(UIUtils.getContext());
        stringStringHashMap.put("appVer", appVersionName);
        HttpUtils.getInstance().executeGet(AppConfig.GET_AD_DIALOG_INFO, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {

            }

            @Override
            protected void onSuccess(String response) {
                Log.e("tag", response);
                if (mvpView != null) {
                    mvpView.getAdDialogInfoSuccess(response);
                }
            }
        });
    }

}
